//
//  AlertViewController.m
//  FineNurse
//
//  Created by TT_UED on 2018/4/20.
//  Copyright © 2018年 TT_UED. All rights reserved.
//

#import "AlertViewController.h"

@interface AlertViewController ()

@end

@implementation AlertViewController


+(UIAlertController*) Alert:(NSString*)message callbackOkFn: (nullable void(^)())callbackYes{
    
    NSString *title = @"提示";
    
    UIAlertController *m = [UIAlertController alertControllerWithTitle: title message:message preferredStyle: UIAlertControllerStyleAlert];
    

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style: UIAlertActionStyleDestructive
                                                     handler:^(UIAlertAction * action) {
                                                             if(callbackYes){
                                                                 callbackYes();
                                                             }
                                                     }];
    [m addAction:okAction];
    
    return m;
}

+(UIAlertController*) Confirm:(NSString*)message callbackOkFn: (void(^)())callbackYes callbackNoFn: (void(^)())callbackCancel{

    NSString *title = @"提示";
    
    UIAlertController *m = [UIAlertController alertControllerWithTitle: title message:message preferredStyle: UIAlertControllerStyleAlert];
    

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style: UIAlertActionStyleDestructive
                                                     handler:^(UIAlertAction * action) {
                                                         if(callbackYes){
                                                             callbackYes();
                                                         }
                                                     }];
    
    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style: UIAlertActionStyleCancel
                                                         handler:^(UIAlertAction * action) {
                                                             if(callbackYes){
                                                                 callbackCancel();
                                                             }
                                                         }];
    
    [m addAction:okAction];
    [m addAction:cancelAction];
    
    return m;
}


+(UIAlertController*) AlertSheet:(NSString*)title message:(NSString*)message sheetsName:(NSArray*)sheets callbackFns:(void(^)())callback {
    
    UIAlertController *m = [UIAlertController alertControllerWithTitle: title message:message preferredStyle: UIAlertControllerStyleActionSheet];
    
    
    int count = [sheets count];
   
    NSLog(@"%i", count);
    
    for (int i = 0; i < sheets.count; i++) {
        
        NSString* sheetName = sheets[i];
        
        UIAlertAction* action = [UIAlertAction actionWithTitle: sheetName
                                                           style: UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {
                                                             callback(i);
                                                         }];
     
        [m addAction:action];
    }
    
    return m;
}


- (void)viewDidLoad {
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
